#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

const int mod = 998244353;
bool fbd[502][501][501];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> C(n + 1, vector<int>(n + 1));
  for (int i = 0; i <= n; i ++) {
    for (int j = 0; j <= i; j ++) {
      if (j == 0 || i == j) C[i][j] = 1;
      else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
  }
  while (m --) {
    int l, r, x;
    cin >> l >> r >> x;
    fbd[l][r][x] = 1;
  }

  vector<vector<i64>> dp(n + 2, vector<i64>(n + 1, 1));
  for (int l = n; l >= 1; l --) {
    for (int r = l; r <= n; r ++) {
      for (int x = l; x <= r; x ++) {
        fbd[l][r][x] |= fbd[l][r - 1][x] | fbd[l + 1][r][x];
      }
      dp[l][r] = 0;
      for (int k = l; k <= r; k ++) {
        if (fbd[l][r][k]) continue;
        dp[l][r] = (dp[l][r] + dp[l][k - 1] * dp[k + 1][r] % mod * C[r - l][k - l]) % mod;
      }
    }
  }
  cout << dp[1][n] << endl;
}